<template>
	<view class="index">
		<NavbarNormal title="活动专区" immersive :background="{background:'#ffffff'}" :backIconImage="backIconImage" backIconSize="24" backIconheight="38" />
		<view class="u-status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
		<view class="navigate" :style="{ height: navbarHeight + 'px' }">
			
		</view>
		<view v-if="bannerList.length">
			<view style="background: #fff;height:24rpx">
			</view>
			<Banner :detail="bannerList"></Banner>
		</view>
		<!-- 为您推荐 -->
		<view class=""  style="height:24rpx">
			
		</view>
		<PromotionGood v-if="goodsList.length" :benefit="goodsList" :showHead="false" />
		<!-- #ifdef H5 -->
		<view class="bottomSpace" style='line-height:100rpx'>正在使用H5方式浏览</view>
		<!-- #endif -->
	</view>
</template>
<script>
	import NavbarNormal from '@/components/navbar-normal'
	import PromotionGood from '@/components/PromotionGood'

	import Banner from './components/Banner'
	import {
		getGroomList,
		getBannerList
	} from "@/api/store";

	import {
		getShare
	} from '@/api/public'

	import {
		openShareAll
	} from '@/libs/wechat'
	// 获取系统状态栏的高度
	let systemInfo = uni.getSystemInfoSync();

	export default {
		name: 'Hot',
		components: {
			PromotionGood,
			Banner,
			NavbarNormal
		},
		data: function() {
			return {
				statusBarHeight: systemInfo.statusBarHeight,
				backIconImage:"/static/index/icon-fanhui@3x.png",
				bannerList: [],
				goodsList: [],
			}
		},
		onLoad() {
			this.getIndexBannerList()
			this.getIndexGroomList()
		},
		computed:{
			navbarHeight() {
				// #ifdef APP-PLUS || H5
				return 44;
				// #endif
				// #ifdef MP
				// 小程序特别处理，让导航栏高度 = 胶囊高度 + 两倍胶囊顶部与状态栏底部的距离之差(相当于同时获得了导航栏底部与胶囊底部的距离)
				// 此方法有缺陷，暂不用(会导致少了几个px)，采用直接固定值的方式
				// return menuButtonInfo.height + (menuButtonInfo.top - this.statusBarHeight) * 2;//导航高度
				let height = systemInfo.platform == 'ios' ? 44 : 48;
				return this.height ? this.height : height;
				// #endif
			},
		},
		methods: {
			onShareTimeline: function() {
				return {
					title: this.miniHomeRemark,
					imageUrl: this.miniHomeImg,
					path: 'pages/home/index?spread=' + uni.getStorageSync('uid'),
				}
			},
			onShareAppMessage: function() {
				return {
					title: this.miniHomeRemark,
					imageUrl: this.miniHomeImg,
					path: 'pages/home/index?spread=' + uni.getStorageSync('uid'),
				}
			},
			getIndexGroomList() {
				let that = this;
				getGroomList(3)
					.then(res => {
						that.goodsList = res.data.list;
						this.setOpenShare()
					})
					.catch((err) => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: 'none',
							duration: 2000
						});
					});
			},
			
			getIndexBannerList() {
				let that = this;
				getBannerList()
					.then(res => {
						that.bannerList = [{
							pic:res.data.value||''
						}];
					})
					.catch((err) => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: 'none',
							duration: 2000
						});
					});
			},
			setOpenShare: function() {
				if (this.$deviceType == 'weixin') {
					getShare().then(res => {
						var data = res.data.data
						var configAppMessage = {
							desc: data.synopsis,
							title: data.title,
							link: location.href,
							imgUrl: data.img,
						}
						openShareAll(configAppMessage)
					})
				}
			},
		},
	}
</script>
<style scoped lang="less">
	.index {
		background-color: #f6f6f6;
	}
</style>